import { IPersonState } from "../State";
import { MinLengthValidator } from "../Validator/MinLengthValidator";
import { RegularExpreesionValidator } from "../Validator/RegularExpreesionValidator";
import { IValidation } from "./IValidation";

export class PhoneNumberValidation implements IValidation {
  private readonly regexValidator: RegularExpreesionValidator = new RegularExpreesionValidator('^1[3456789]\\d{9}');
  private readonly minLengthValidator: MinLengthValidator = new MinLengthValidator(1);

  public Validate(state: IPersonState, errors: string[]): void {
    if (!this.minLengthValidator.IsValid(state.PhoneNumber)) {
      errors.push('请输入手机号码');
    } else if (!this.regexValidator.IsValid(state.PhoneNumber)) {
      errors.push('请输入正确的手机号码');
    }
  }
}